import {createRouter, createWebHistory} from 'vue-router'
import Login from '../views/Login/index.vue'
import Layout from '../views/Layout/index.vue'
import Home from '@/views/Home/index.vue'
import Category from '@/views/Category/index.vue'
import SubCategory from '@/views/SubCategory/index.vue'
import Detail from '@/views/Detail/index.vue'
import CartList from '@/views/CartList/index.vue'
import Checkout from '@/views/Checkout/index.vue'
import Pay from '@/views/Pay/index.vue'
import PayBack from '@/views/Pay/PayBack.vue'
import Member from '@/views/Member/index.vue'
import UserInfo from '@/views/Member/components/UserInfo.vue'
import UserOrder from '@/views/Member/components/UserOrder.vue'

const routes = [
  {
    path: '/',
    name: 'layout',
    component: Layout,
    children: [
      {
        path: '',
        name: '首页',
        component: Home
      },
      {
        path: 'category/:id',
        name: '分类',
        component: Category
      },
      {
        path: 'detail/:id',
        name: '详情',
        component: Detail
      },
      {
        path: 'category/sub/:id',
        name: '二级分类',
        component: SubCategory
      },
      {
      path:'cartlist',
        name:'购物车',
        component: CartList
      },
      {
        path:'checkout',
        name:'结账',
        component: Checkout
      },
      {
        path: 'pay',
        name:'支付',
        component: Pay
      },
      {
        path: 'paycallback',
        name:'支付结果',
        component: PayBack
      },
      {
        path: 'member',
        name:'会员',
        component: Member,
        children: [
          {
            path:'',
            name:'个人中心',
            component: UserInfo,
          },
          {
            path:'order',
            name:'订单管理',
            component: UserOrder,
          },
        ]
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: Login
  }
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
  scrollBehavior() {
    return {top: 0}
  }
})

router.afterEach(to => {
  document.title="小兔鲜儿->>"+to.name
})

export default router
